
#include<stdio.h>
#include <stdlib.h>

#define MaxSize 50
#define max_size 5
typedef int ElemType;
typedef struct {
    ElemType data[MaxSize];
    int top;
} SqStack;

typedef struct {
    ElemType data[max_size];
    int rear, front;
} SqQueue;

void InitStack(SqStack &s) {
    s.top = -1;
}

void PushStack(SqStack &s, ElemType element) {
    if (s.top == MaxSize - 1) {
        return;
    }
    s.data[++s.top] = element;
}

void PopStack(SqStack &s, ElemType &num) {
    if (s.top == -1) {
        return;
    }
    num = s.data[s.top--];
}

//初始化循环队列
void InitQueue(SqQueue &Q) {
    Q.front = Q.rear = 0;//初始化循环队列，头和尾指向0
}

//判断队列是否为空
bool IsEmptyQueue(SqQueue Q) {
    return Q.rear == Q.front;
}

bool EnQueue(SqQueue &Q, ElemType num) {
    //判断队列元素是否满了，若满了则不入队
    if ((Q.rear + 1) % max_size == Q.front) {
        return false;
    }
    Q.data[Q.rear] = num;
    //如果大于数组最大下标则回到开头
    Q.rear = (Q.rear + 1) % max_size;
    return true;
}


bool DeQueue(SqQueue &Q, ElemType &num) {
    //出队之前先对队中元素进行判断，若为空则返回
    if (IsEmptyQueue(Q)) return false;
    num = Q.data[Q.front];//出队
    Q.front = (Q.front + 1) % max_size;
    return true;
}

int main() {
    SqStack s;
    //初始化栈
    InitStack(s);
    //入栈
    //入栈之前先判断栈是否为空
    for (int i = 0; i < 3; i++) {
        int n;
        scanf("%d", &n);
        PushStack(s, n);
    }
    SqQueue Q;
    //初始化循环队列
    InitQueue(Q);
    bool ret;
    //入队
    for (int i = 0; i < 5; i++) {
        int n;
        scanf("%d", &n);
        ret=EnQueue(Q, n);
    }

    //出栈
    for (int i = 0; i < 3; i++) {
        ElemType num;
        PopStack(s, num);
        printf("%2d", num);
    }
    printf("\n");

    if(!ret) printf("false\n");

    //出队
    for (int i = 0; i < 4; i++) {
        ElemType number;
        DeQueue(Q, number);
        printf("%2d",number);
    }
    return 0;
}
